//
//  HNSH_WithdrawalRecordViewController.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/6/14.
//

#import "HNSH_WithdrawalRecordViewController.h"

#import "HNSH_WithdrawalRecordCell.h"
#import "HNSH_WithdrawalRecordModel.h"

@interface HNSH_WithdrawalRecordViewController ()

/* listAry */
@property (nonatomic, strong) NSMutableArray *listAry;

@end

static NSString *HNSH_WithdrawalRecordCellID = @"HNSH_WithdrawalRecordCellID";

@implementation HNSH_WithdrawalRecordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor colorWithHexString:@"#F4F4F4"];
    [self showNavTitle:@"提现记录" showLeftItem:YES];
    
    [self configTableView];
}

- (void)configTableView {
    [self.tableView registerClass:[HNSH_WithdrawalRecordCell class] forCellReuseIdentifier:HNSH_WithdrawalRecordCellID];
    
    self.tableView.backgroundColor = [UIColor appBGColor];
    self.tableView.rowHeight = 64;
    self.tableView.estimatedRowHeight = 64;
    
    [self setupRefresh:self.tableView option:ST_RefreshDefault];
}

- (void)refreshData:(NSInteger)page {
    [HNSH_UserNetServer requestUserWithdrawRecordWithPage:page success:^(ST_BaseNetModel * _Nullable responseObject) {
        if (responseObject.code == 0) {
            NSArray *ary = [NSArray yy_modelArrayWithClass:[HNSH_WithdrawalRecordModel class] json:responseObject.resultset[@"list"]];
            if (page == 1) {
                [self.listAry removeAllObjects];
            }
            [self.listAry addObjectsFromArray:ary];
            [self.tableView reloadData];
            [self endRefresh:ary.count > 10];
        }
    } Failure:^(NSError * _Nullable error) {
        
    }];
}

#pragma mark - UITableViewDataSource Methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.listAry.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 12.0f;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.01f;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [UIView new];
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [UIView new];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HNSH_WithdrawalRecordCell * cell = [tableView dequeueReusableCellWithIdentifier:HNSH_WithdrawalRecordCellID forIndexPath:indexPath];
    cell.model = self.listAry[indexPath.section];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

}

- (NSMutableArray *)listAry {
    if (!_listAry) {
        _listAry = [NSMutableArray arrayWithCapacity:0];
    }
    return _listAry;
}

@end
